<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet"  href="/layui/css/layui.css"/>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>健康资讯列表</title>
</head>
<body>
<script src="/plugins/jquery/jquery-1.10.2.min.js"></script>
<script  src="/layui/layui.js"></script>
<script src="/plugins/js/common.js"></script>
<form class="layui-form">
	<label class="layui-form-label">资讯标题：</label>
    <div class="layui-input-inline">
        <input type="text" name="title" id="title" autocomplete="off"  placeholder="请输入资讯标题" class="layui-input">
    </div>
    <div class="layui-inline">
<!--             <button class="layui-btn layuiadmin-btn-forum-list" id="searchButton" data-type="reload"> -->
<!--               <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> -->
<!--             </button> -->
			 <button class="layui-btn" data-type="reload" id="searchButton" onclick="return search();">搜索</button>
          </div>
	  <div style="margin-left: 5px;">
	          <button class="layui-btn layuiadmin-btn-replys" onclick="return toAdd();">新增</button>
	  </div>        
</form>
<table class="layui-hide" id="healthInfoList"  lay-filter="healthInfoList"></table>
<script type="text/html" id="healthInfoListBarAction">
  <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript">
var table;
var layer;
layui.use(['table'], function(){
	layer=layui.layer;
	  table = layui.table;
	  tableIns = initTable(table);
	//监听行工具事件
	  table.on('tool(healthInfoList)', function(obj){
	    var data = obj.data;
	    if(obj.event === 'del'){
	    	layer.confirm('确认要删除吗？', {
	    		  btn: ['确认','取消'] //按钮
	    		}, function(){
	    		  var deleteResult = ajaxAction("/healthInfo/deleteHealthInfo",{id:data.id});
	    		  if(deleteResult){
	    			  search("删除成功");
	    		  }else{
	    			  layer.msg('删除失败', {icon: 5});
	    		  }
	    		});
	    } else if(obj.event === 'edit'){
	    	toUpdate(data.id);
	    }else{
	    	toDetail(data.id);
	    }
	  });
});

function initTable(){
	table.render({
	    elem: '#healthInfoList',
	    url:'/healthInfo/listData',
	    cellMinWidth: 90,
	    cols:[
		    	[
			      {field:'title' ,title: '资讯标题'},
			      {field:'status',  title: '发布状态',templet:function(value){
			    	  if(value.status==1){
			    		  return "已发布";
			    	  }else if(value.status==2){
			    		  return "未发布";
			    	  }
			      	}
			      },
			      {field:'updateDate', width:200, title: '操作时间',sort : true,fixed:false,templet:'<div>{{ formatDate(d.updateDate)}}</div>'},
			      {fixed: 'right', title:'操作', toolbar: '#healthInfoListBarAction'}
		    	]
	    ],page: true,
	    limit:8,
	    where: {
		    'title':$("#title").val()
	    },
	    id: 'reloadTable'
	  });
}


	
	function search(sender){
		var name = $('#name');
	      //执行重载
	      table.reload('reloadTable', {
	        page: {
	          curr: 1 //重新从第 1 页开始
	        }
	        ,where: {
	        	name: name.val()
	        }
	      });
	      if(!isNull(sender)){
	    	  layMsg(sender,2000);
	      }
	      return false;
	}

	function toAdd(){
		perContent = layer.open({
			         type:2,
			         title: "新增健康资讯",
			         content: '/healthInfo/toAddHealthInfo',
			         area: ['700px', '420px'],
			         maxmin: true,            //最大化按钮
			         anim:3,                    //动画
			         shade: [0.8, '#393D49'],//遮罩层
			         end: function(){
// 			        	 alert(1);
		            }
// 		            btn: ['提交','关闭'],
		           /* yes:function(index, layero){
		            	var iframeWin = window["layui-layer-iframe" + index];
		            	iframeWin.addUser();
		                layer.close(index);
		                search();
		            },*/
			     });
		      layer.full(perContent);
		     return false;
	}
	
	function toUpdate(id){
		perContent = layer.open({
	         type:2,
	         title: "编辑健康资讯",
	         content: '/healthInfo/toUpdateHealthInfo?id='+id,
	         area: ['700px', '420px'],
	         maxmin: true,            //最大化按钮
	         anim:3,                    //动画
	         shade: [0.8, '#393D49'],//遮罩层
	         end: function(){
           }
	     });
     layer.full(perContent);
    return false;
}
	
	function toDetail(id){
		perContent = layer.open({
	         type:2,
	         title: "查看健康资讯",
	         content: '/healthInfo/toDetailHealthInfo?id='+id,
	         area: ['700px', '420px'],
	         maxmin: true,            //最大化按钮
	         anim:3,                    //动画
	         shade: [0.8, '#393D49'],//遮罩层
	         end: function(){
           }
	     });
     layer.full(perContent);
    return false;
}
	
	
</script>
<style>
.layui-table-cell{
    height:23px;
    line-height:23px;
}
</style>
</body>
</html>